/***************************************************************************
*   Copyright (C) 2006 by Yuri Ovcharenko                                 *
*   amwsoft@gmail.com                                                     *
*                                                                         *
*   This program is free software; you can redistribute it and/or modify  *
*   it under the terms of the GNU General Public License as published by  *
*   the Free Software Foundation; either version 2 of the License, or     *
*   (at your option) any later version.                                   *
*                                                                         *
*   This program is distributed in the hope that it will be useful,       *
*   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
*   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
*   GNU General Public License for more details.                          *
*                                                                         *
*   You should have received a copy of the GNU General Public License     *
*   along with this program; if not, write to the                         *
*   Free Software Foundation, Inc.,                                       *
*   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
***************************************************************************/
#include "consolesettings.h"

#include <QtGui>

ConsoleSettings::ConsoleSettings( QWidget *parent )
    : QDialog( parent )
{
  QVBoxLayout *lv;
  QHBoxLayout *lh;
  QGridLayout *lg;
  QSpacerItem *sp;
  QPushButton *b;

  lv = new QVBoxLayout(this);

  lg = new QGridLayout();
  lv->addLayout(lg);

  lg->addWidget(new QLabel(tr("Width: ")), 0, 0);
  sbWidth = new QSpinBox();
  sbWidth->setRange(1, 256);
  lg->addWidget(sbWidth, 0, 1);

  lg->addWidget(new QLabel(tr("Height: ")), 1, 0);
  sbHeight = new QSpinBox();
  sbHeight->setRange(1, 256);
  lg->addWidget(sbHeight, 1, 1);

  cbHex = new QCheckBox(tr("Display HEX"));
  lg->addWidget(cbHex, 2, 0, 1, -1);

  lg->addWidget(new QLabel(tr("Font: ")), 3, 0);
  cbFont = new QFontComboBox();
  cbFont->setFontFilters(QFontComboBox::MonospacedFonts/* | QFontComboBox::NonScalableFonts*/);
  lg->addWidget(cbFont, 3, 1);


  lh = new QHBoxLayout();
  lv->addLayout(lh);
  sp = new QSpacerItem(10, 1, QSizePolicy::Expanding, QSizePolicy::Fixed);
  lh->addItem(sp);

  b = new QPushButton(tr("OK"));
  connect(b, SIGNAL(clicked()), this, SLOT(accept()));
  lh->addWidget(b);

  b = new QPushButton(tr("Cancel"));
  connect(b, SIGNAL(clicked()), this, SLOT(reject()));
  lh->addWidget(b);
}

ConsoleSettings::~ConsoleSettings()
{
}

void ConsoleSettings::settings(QSize & sz, bool & hex, QString & fnt)
{
  sz.setWidth(sbWidth->value());
  sz.setHeight(sbHeight->value());
  hex = cbHex->isChecked();
  fnt = cbFont->currentFont().family();
}

void ConsoleSettings::setSettings(const QSize & sz, const bool hex, const QString & fnt)
{
  sbWidth->setValue(sz.width());
  sbHeight->setValue(sz.height());
  cbHex->setChecked(hex);
  cbFont->setCurrentFont(QFont(fnt, 10));
  int i = cbFont->findText(fnt);
  if (i >= 0)
    cbFont->setCurrentIndex(i);
}

/* End of file */
